export default {
  set(key, data, expire) {
    let cache = {data}
    if (expire) {
      cache.expire = new Date().getTime() + data.expire * 1000
    }
    localStorage.setItem(key, JSON.stringify(cache))
  },

  get(key) {
    const cacheStore = localStorage.getItem(key)
    if (!cacheStore) {
      return null
    }

    const cache = JSON.parse(cacheStore)
    const expire = cache.expire
    if (expire && expire < new Date().getTime()) {
      localStorage.removeItem(key)
      return null
    }

    return cache.data
  },

  remove(key) {
    localStorage.removeItem(key)
  },
}
